<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>物料审核</title>
    <link rel="stylesheet" href="../../css/pintuer.css">
    <link rel="stylesheet" href="../../css/admin.css">
    <link rel="stylesheet" href="../../css/bootstrap.css">
    <style>
        input{
            border-top: none;
            border-left: none;
            border-right: none;
            border-bottom: black solid 1px;
        }
        table{
            border: 1px;
            cell-padding:0;
            cell-spacing:0;
            width: 80%;
            margin-top: 20px;
        }
        table thead{
            background-color:#b3d7ff ;
        }
        a{
            cursor: pointer;
        }
    </style>
</head>
<body bgcolor="#dcdcdc">
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/bootstrap.min.js"></script>
<script src="../../js/bootstrap-table1.15.3.js"></script>
<script>
    var thisUrl=document.URL;
    var getval=thisUrl.split("?")[1];
    var showval=getval.split("=")[1];
    function init(){
        $.ajax({
            url:'/design/selectById',
            data:'id='+showval,
            type:'get',
            success:function (data) {

                $('input[name="id"]').val(data.id);

                $('#designId').text(data.designId);
                $('#productName').text(data.productName);
                $('#productId').text(data.productId);

                $('#costPriceSum').text(data.costPriceSum);

                $('input[name="designer"]').val(data.register);

                var username = localStorage.getItem("userName");
                $('input[name="checker"]').val(username);

                var myDate = new Date;
                var year = myDate.getFullYear();
                var mon = myDate.getMonth() + 1;
                var date = myDate.getDate();
                var h = myDate.getHours();//获取当前小时数(0-23)
                var m = myDate.getMinutes();//获取当前分钟数(0-59)
                var s = myDate.getSeconds();//获取当前秒
                $('input[name="checkTime"]').val(year+"-"+mon+'-'+date+' '+h+':'+m+':'+s);

            }
        })
        $.ajax({
            url:'/design/selectDetail.action',
            data:'id='+showval,
            type:'post',
            success:function (data) {
                // alert(1);
                var tb = $('#tbodyId');
                tb.empty();
                for( var i = 0 ; i < data.length ; i++ ){

                    var trObj = $('<tr>');

                    var id = $('<td>').text(data[i].id);
                    trObj.append(id);

                    var pName = $('<td>').text(data[i].productName);
                    trObj.append(pName);

                    var pid = $('<td>').text(data[i].productId);
                    trObj.append(pid);

                    var type = $('<td>').text(data[i].type==="Y001-1"?"商品":"物料");
                    trObj.append(type);

                    var count = $('<input class="countClass" type="text" size="3px">');
                    count.val(data[i].amount);
                    var tdAmount = $('<td>');
                    tdAmount.append(count);
                    trObj.append(tdAmount);

                    var amountUnit = $('<td>').text(data[i].amountUnit);
                    trObj.append(amountUnit);

                    var costPrice = $('<td>').text(data[i].costPrice);
                    trObj.append(costPrice);

                    var subtotal = $('<td>').text(data[i].subtotal);
                    trObj.append(subtotal);

                    tb.append(trObj);
                }
            }
        })
    }
    $(function () {
      init();
      $('#composite').click(function () {

          var check = $('input[name="check"]:checked').val();

          var module = new Object();
          module.id = $('input[name="id"]').val();
          module.designId = $('#designId').text();
          module.productName = $('#productName').text();
          module.productId = $('#productId').text();
          module.costPriceSum = $('#costPriceSum').text();
          module.designer = $('input[name="designer"]').val();
          module.checker =$('input[name="checker"]').val();
          module.checkTime = $('input[name="checkTime"]').val();


          //创建一个对象数组
          var arr=[];
          //拿取表格中的值，放到SGatherDetails类中
          for(var i=0;i<$('#tbodyId tr').length;i++){
              //获取每一行的对象tr
              let trObj = $('#tbodyId tr').get(i);
              //new 一个对象
              var details = new Object();
              //获取值
              details.productId = trObj.children[1].innerText;
              details.productName = trObj.children[2].innerText;
              if (trObj.children[3].innerText==="物料"){
                  details.type = "Y001-2";
              }else{
                  details.type = "Y001-1";
              }
              details.amount = $('.countClass').eq(i).val();
              details.amountUnit = trObj.children[5].innerText;
              details.costPrice = trObj.children[6].innerText;
              details.subtotal = trObj.children[7].innerText;
              details.desidualAmount = details.amount;
              //存到对象数组中
              arr.push(details);
          }
          $.ajax({
              type:'post',
              url:'/design/materielComposite.action',
              data:'design='+JSON.stringify(module)+'&details='+JSON.stringify(arr)+'&check='+check,
              success:function (data) {
                  if (data>0){
                      alert('物料组成设计单审核完成');
                      window.location='materielPro.html';
                  }else{
                      alert('物料组成设计单审核失败');
                  }
              }
          });


        });
      $('#btn_return').click(function () {
        btn_return();
      });
    })
    function btn_return() {
        window.location="pro/materiel/materialComposite.html";
    }
</script>
<div class="container-fluid">
    <div class="row" style="margin-top: 50px;">
        <div class="col-12">
            <div style="width: 60%;margin: 0 auto;">
                <div class="col-12 offset-12" style="text-align: right" id="btnDivId">
                    <input type="radio" checked="checked" name="check" value="0">通过
                    <input type="radio" name="check" value="1">不通过
                    <button class="btn btn-success btn-sm" id="composite">确认</button>
                    <button class="btn btn-primary btn-sm" id="btn_return">返回</button>
                </div>
            </div>
        </div>
        <div class="col-12">
            <div style="width: 60%;height: 550px;border: 2px solid gray;margin: 0 auto;margin-top: 10px">
                <h3 align="center" style="margin-top: 30px">物料组成设计单</h3>
                <div class="container-fluid">
                    <form id="MaterialFormId">
                        <input type="hidden" name="id">
                        <div class="row">
                            <div class="col-2">
                                设计单编号：
                            </div>
                            <div class="col-4" style="padding-left: 0px;margin-left: 0px;">
                                <span id="designId"></span>
                            </div>
                            <div class="col-2">
                                设计人：
                            </div>
                            <div class="col-4">
                                <input name="designer" id="designer">
                            </div>
                        </div>

                        <div class="row" style="margin-top: 30px;">
                            <div class="col-2">
                                产品名称：
                            </div>
                            <div class="col-4" style="padding-left: 0px;margin-left: 0px;">
                                <span id="productName"></span>
                            </div>
                            <div class="col-2">
                                产品编号：
                            </div>
                            <div class="col-4" style="padding-left: 0px;margin-left: 0px;">
                                <span id="productId"></span>
                            </div>
                        </div>

                        <div>
                            <table width="80%" style="margin-top: 20px;text-align: center;" class="table table-sm">
                                <thead  style="background-color: #b3d7ff;">
                                <tr>
                                    <th>序号</th>
                                    <th>物料编号</th>
                                    <th>物料名称</th>
                                    <th>用途类型</th>
                                    <th>数量</th>
                                    <th>单位</th>
                                    <th>计划成本单价（元）</th>
                                    <th>小计（元）</th>
                                </tr>
                                </thead>
                                <tbody id="tbodyId" align="center">

                                </tbody>
                            </table>
                        </div>

                        <div class="row" style="margin-top: 20px;">
                            <div class="col-2">
                                物料总成本：
                            </div>
                            <div class="col-2">
                                <span id="costPriceSum"></span>
                            </div>

                        </div>

                        <div class="row" style="margin-top: 30px;">
                            <div class="col-2">
                                审核人：
                            </div>
                            <div class="col-4">
                                <input  name="checker" id="checker">
                            </div>
                            <div class="col-2">
                                审核时间：
                            </div>
                            <div class="col-4">
                                <input name="checkTime" id="checkTime">
                            </div>
                        </div>

                        <div style="margin-top: 30px;">
                            <span>设计要求：</span>
                            <textarea cols="70%" rows="3" name="moduleDescribe" id="remark"></textarea>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


</body>
</html>